Hack scrollwheel support into the eventloop, by treating button 4-5
authorOwen Taylor <otaylor@redhat.com>
Thu, 28 Jan 1999 00:57:18 +0000 (00:57 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Thu, 28 Jan 1999 00:57:18 +0000 (00:57 +0000)
Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>

* gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
support into the eventloop, by treating button 4-5
presses on scrolled windows and scrollbars specially.
Put it here to keep the ugliness small and confined.
(We need to intercept the normal propagation in any case
to have this work reliably right now, since some
subwidgets will trap the button presses)

* gtk/gtkviewport.c (gtk_viewport_realize): Select for
BUTTON_PRESS to support the above hack.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkmain.c
gtk/gtkviewport.c

index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index 5d6ca7eea532261bb962e8b4061bb0b91c78c380..2b4f3123715e41e683f0a55e9332eab021456c7b 100644 (file)
@@ -1,3 +1,16 @@
+Wed Jan 27 18:40:50 1999  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel
+       support into the eventloop, by treating button 4-5
+       presses on scrolled windows and scrollbars specially. 
+       Put it here to keep the ugliness small and confined.
+       (We need to intercept the normal propagation in any case
+       to have this work reliably right now, since some
+       subwidgets will trap the button presses)
+       
+       * gtk/gtkviewport.c (gtk_viewport_realize): Select for 
+       BUTTON_PRESS to support the above hack.
+       
 Tue Jan 26 14:02:50 1999  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's
index f573c9db1124c89cf4c2b2aa7a01cb1dceed9b1a..62f337fa6e3562411b3b384025c0ce469ea2e812 100644 (file)
@@ -29,6 +29,7 @@
 #include "gtkmain.h"
 #include "gtkpreview.h"
 #include "gtkrc.h"
+#include "gtkscrolledwindow.h"
 #include "gtkselection.h"
 #include "gtksignal.h"
 #include "gtktable.h"
@@ -629,7 +630,7 @@ gtk_main_do_event (GdkEvent *event)
     {
       grab_widget = event_widget;
     }
-  
+
   /* Not all events get sent to the grabbing widget.
    * The delete, destroy, expose, focus change and resize
    *  events still get sent to the event widget because
@@ -675,7 +676,49 @@ gtk_main_do_event (GdkEvent *event)
     case GDK_VISIBILITY_NOTIFY:
       gtk_widget_event (event_widget, event);
       break;
-      
+
+    case GDK_BUTTON_PRESS:
+    case GDK_2BUTTON_PRESS:
+    case GDK_3BUTTON_PRESS:
+    /* We treat button 4-5 specially, assume we have
+     * a MS-style scrollwheel mouse, and try to find
+     * a plausible widget to scroll. We also trap
+     * button 4-5 double and triple clicks here, since
+     * they will be generated if the user scrolls quickly.
+     */
+      if ((grab_widget == event_widget) &&
+         (event->button.button == 4 || event->button.button == 5))
+       {
+         GtkWidget *range = NULL;
+         GtkWidget *scrollwin;
+         
+         if (GTK_IS_RANGE (event_widget))
+           range = event_widget;
+         else
+           {
+             scrollwin = gtk_widget_get_ancestor (event_widget,
+                                                  GTK_TYPE_SCROLLED_WINDOW);
+             if (scrollwin)
+               range = GTK_SCROLLED_WINDOW (scrollwin)->vscrollbar;
+           }
+         
+         if (range && GTK_WIDGET_VISIBLE (range))
+           {
+             if (event->type == GDK_BUTTON_PRESS)
+               {
+                 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
+                 gfloat new_value = adj->value + ((event->button.button == 4) ? 
+                                                  -adj->page_increment / 2: 
+                                                   adj->page_increment / 2);
+                 new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
+                 gtk_adjustment_set_value (adj, new_value);
+               }
+             break;
+           }
+       }
+      gtk_propagate_event (grab_widget, event);
+      break;
+
     case GDK_KEY_PRESS:
     case GDK_KEY_RELEASE:
       if (key_snoopers)
@@ -685,9 +728,6 @@ gtk_main_do_event (GdkEvent *event)
        }
       /* else fall through */
     case GDK_MOTION_NOTIFY:
-    case GDK_BUTTON_PRESS:
-    case GDK_2BUTTON_PRESS:
-    case GDK_3BUTTON_PRESS:
     case GDK_BUTTON_RELEASE:
     case GDK_PROXIMITY_IN:
     case GDK_PROXIMITY_OUT:
index 168ff0317d95a450679df2995b6b7e51452ad3d8..6964206fe17845c772b5ab8134eafbb23533d590 100644 (file)
@@ -430,7 +430,9 @@ gtk_viewport_realize (GtkWidget *widget)
   attributes.colormap = gtk_widget_get_colormap (widget);
 
   event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
-  attributes.event_mask = event_mask;
+  /* We select on button_press_mask so that button 4-5 scrolls are trapped.
+   */
+  attributes.event_mask = event_mask | GDK_BUTTON_PRESS_MASK;
 
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;